package com.cq.hd.system.controller;

import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.ResultGenerator;
import com.cq.hd.system.api.TbRegionsApi;
import com.cq.hd.system.api.vo.RegionVo;
import com.cq.hd.system.service.TbRegionsService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 地区(es_regions) 前端控制器
 * </p>
 *
 * @author mYunYu
 * @since 2023-11-22
 */
@RestController
public class TbRegionsController implements TbRegionsApi {

    @Autowired
    private TbRegionsService regionsService;

    @ApiOperation(value = "根据id获取省市列表数据")
    @ApiImplicitParam(name = "id", value = "id:0：获取省份，其他id：获取市区数据", required = true, defaultValue = "0", paramType = "query", dataType = "Integer")
    @ApiResponse(response = RegionVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<List<RegionVo>> listRegion(Integer id) {
        return ResultGenerator.success(regionsService.listRegion(id));
    }

    @ApiOperation(value = "获取省市列表所有数据")
    @ApiResponse(response = RegionVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<List<RegionVo>> listAllRegion(String cityName) {
        return ResultGenerator.success(regionsService.listAllRegion(cityName));
    }
}
